package jmx.study.riclient;


import java.io.IOException;
import java.util.concurrent.TimeUnit;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

/**
 * 模拟TAM
 * 链接RI后台MBean,订阅消息,并处理消息
 * @author zhenzhen
 *
 */
public class RiEventClient
{
    public static void main(String[] args) throws IOException, Exception, NullPointerException
    {
    	//建立链接
    	String urlString = "service:jmx:rmi://ip:6300/jndi/rmi://ip:6300/jmxDefault";
        JMXServiceURL url = new JMXServiceURL(urlString);
        JMXConnector jmxc = JMXConnectorFactory.connect(url,null);
        MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
       
        
        //ObjectName名称为:需要监听的MBean名字
        ObjectName mbeanName = new ObjectName("RICA_ip:name=Event");
        //添加监听器处理映射: mbeanName --> RemoteRiNotificationListener
        mbsc.addNotificationListener(mbeanName, new RiNotificationListener(), null, null);
        
        TimeUnit.MINUTES.sleep(60);
    }
}
